<template>
    <div class="P-parents page">
        <div class="content">
            <PlatformCrumb back="教练资料">
                <button class="coach-blue" @click="godetail">编辑资料</button>
            </PlatformCrumb>
            <div class="p-parcoach-detail my-deta-con">
                <p class="title">基本资料</p>
                <div class="p-parcoach-data display-flex-row">
                    <div class="display-flex-column">
                        <img :src="datalist.imgs|filtersImg"/>
                        <div class="display-flex-row star-rate">
                            <div>星级：</div>
                            <div class="date-star">
                                <el-rate disabled v-model="datalist.rank"></el-rate>
                            </div>
                        </div>

                    </div>

                    <div class="coach-con-center">
                        <div class="coach-con-center-item">
                            <p><span>姓名</span>{{datalist.name }}</p>
                            <p><span>学历</span>{{datalist.xl }}</p>
                            <p><span>毕业院校</span>{{datalist.graduatedFrom }}</p>
                            <p><span>联系电话</span>{{datalist.phone }}</p>
                            <p><span>微信</span>{{datalist.weChatNo}} <strong>已绑定</strong></p>
                            <p><span>教练等级</span>{{datalist.coachLevel|filterstype(optionsJLDJ)}} </p>
                        </div>
                        <div class="coach-con-center-item">
                            <p><span>邮箱</span>{{datalist.mail}} </p>
                            <p><span>证件号码</span>{{datalist.leaderNo}} </p>
                            <p><span>联系地址</span>{{datalist.address}} </p>
                            <p><span>语言能力</span>{{datalist.yy|filterstype(optionsYYNL)}} </p>
                            <p><span>机构</span>{{datalist.mechanismId}} </p>
                            <p><span>座右铭</span>{{datalist.motto}}</p>
                        </div>
                    </div>
                </div>
                <div class="mydate-cv">
                    履历:
                </div>

                <div class="mydate-cv-list">
                    <div class="mydate-cv-item" v-for="(item,index) in Resumelist" :key="index">
                        <span>{{item.startTime|filtersdata }}至{{item.endTime|filtersdata}}</span>
                        {{item.address}} {{item.position}}
                    </div>
                </div>

            </div>


        </div>
    </div>

</template>

<script>
    import {mapActions, mapState} from 'vuex'
    import PlatformCrumb from "@/components/PlatformCrumb.vue";
    import {basefile, imgupload} from '@/config/env.js';

    function formatDate(timeStamp, type = 'Y-M-D H:I:S', auto = false) {
        let time = (timeStamp + '').length === 10 ? new Date(parseInt(timeStamp) * 1000) : new Date(parseInt(timeStamp));
        let _year = time.getFullYear();
        let _month = (time.getMonth() + 1) < 10 ? '0' + (time.getMonth() + 1) : (time.getMonth() + 1);
        let _date = time.getDate() < 10 ? '0' + time.getDate() : time.getDate();
        let _hours = time.getHours() < 10 ? '0' + time.getHours() : time.getHours();
        let _minutes = time.getMinutes() < 10 ? '0' + time.getMinutes() : time.getMinutes();
        let _secconds = time.getSeconds() < 10 ? '0' + time.getSeconds() : time.getSeconds();
        let formatTime = '';
        let distinctTime = new Date().getTime() - time.getTime();

        if (auto) {
            if (distinctTime <= (1 * 60 * 1000)) {
                // console.log('一分钟以内，以秒数计算');
                let _s = Math.floor((distinctTime / 1000) % 60);
                formatTime = _s + '秒前';
            } else if (distinctTime <= (1 * 3600 * 1000)) {
                // console.log('一小时以内,以分钟计算');
                let _m = Math.floor((distinctTime / (60 * 1000)) % 60);
                formatTime = _m + '分钟前';
            } else if (distinctTime <= (24 * 3600 * 1000)) {
                // console.log('一天以内，以小时计算');
                let _h = Math.floor((distinctTime / (60 * 60 * 1000)) % 24);
                formatTime = _h + '小时前';
            } else if (distinctTime <= (30 * 24 * 3600 * 1000)) {
                let _d = Math.floor((distinctTime / (24 * 60 * 60 * 1000)) % 30);
                formatTime = _d + '天前';
                // console.log('30天以内,以天数计算');
            } else {
                // 30天以外只显示年月日
                formatTime = _year + '-' + _month + '-' + _date;
            }
        } else {

            switch (type) {
                case 'Y-M-D H:I:S':
                    formatTime = _year + '-' + _month + '-' + _date + ' ' + _hours + ':' + _minutes + ':' + _secconds;
                    break;
                case 'Y-M-D H:I:S zh':
                    formatTime = _year + '年' + _month + '月' + _date + '日  ' + _hours + ':' + _minutes + ':' + _secconds;
                    break;
                case 'Y-M-D H:I':
                    formatTime = _year + '-' + _month + '-' + _date + ' ' + _hours + ':' + _minutes;
                    break;
                case 'Y-M-D H':
                    formatTime = _year + '-' + _month + '-' + _date + ' ' + _hours;
                    break;
                case 'Y-M-D':
                    formatTime = _year + '-' + _month + '-' + _date;
                    break;
                case 'Y-M-D zh':
                    formatTime = _year + '年' + _month + '月' + _date + '日';
                    break;
                case 'Y-M':
                    formatTime = _year + '-' + _month;
                    break;
                case 'Y':
                    formatTime = _year;
                    break;
                case 'M':
                    formatTime = _month;
                    break;
                case 'D':
                    formatTime = _date;
                    break;
                case 'H':
                    formatTime = _hours;
                    break;
                case 'I':
                    formatTime = _minutes;
                    break;
                case 'S':
                    formatTime = _secconds;
                    break;
                default:
                    formatTime = _year + '-' + _month + '-' + _date + ' ' + _hours + ':' + _minutes + ':' + _secconds;
                    break;
            }
        }
        // 返回格式化的日期字符串
        return formatTime;
    }

    export default {
        data() {
            return {
                datalist: {},
                Resumelist: [],
                value1: '',
                optionsXL: [],
                optionsJLDJ: [],
                optionsYYNL: [],
                id: sessionStorage.getItem('statusId') ? parseInt(sessionStorage.getItem('statusId')) : 0,

            }
        },
        components: {
            PlatformCrumb,
        },
        computed: {
            ...mapState('Login', [
                'userStatus'
            ]),

            id() {
                return this.userStatus.statusId
            }
        },

        methods: {
            ...mapActions('coachTraining', [
                'fetchMydate'
            ]),
            ...mapActions('coachTraining', [
                'getPlayerDetail',
                'fetchSelectList',
                'editPlayerInfo',
                'woundLogsgetList',
                'woundLogsedit',
                'woundLogsget',
                'woundLogsadd',
                'abilityaddScore',
                'abilitygetList',
                'addGroup',
                'coacheditMyInfo',
                'coachget',
                'fetchMydate',
                'resumeadd',
                'resumeedit',
                'resumegetList',
            ]),
            godetail() {
                var that = this;
                that.$router.push({
                    path: '/coach/myDateEdit',
                })
            },
            fetchDate() {
                let id = this.id
                this.fetchMydate({id}).then(res => {
                    const {code} = res
                    if (code === 200) {
                        this.datalist = res.data
                    }
                })
            },
            getresumegetList() {
                const id = this.id
                this.resumegetList({id}).then(res => {
                    const {code, data: {list}} = res
                    if (code === 200) {
                        this.Resumelist = list || []
                    }
                })
            },
            getSelectKC() {
                this.fetchSelectList({type: 'CT'}).then(res => {
                    const {code, data: {list}} = res
                    if (code === 200) {
                        this.optionsKC = list || []
                    }
                })
            },
            getSelectJQ() {
                this.fetchSelectList({type: 'JQ'}).then(res => {
                    const {code, data: {list}} = res
                    if (code === 200) {
                        this.optionsJQ = list || []
                    }
                })
            },
            getSelectXL() {
                this.fetchSelectList({type: 'XL'}).then(res => {
                    const {code, data: {list}} = res
                    if (code === 200) {
                        this.optionsXL = list || []
                    }
                })
            },
            getSelectYYNL() {
                this.fetchSelectList({type: 'YYNL'}).then(res => {
                    const {code, data: {list}} = res
                    if (code === 200) {
                        this.optionsYYNL = list || []
                    }
                })
            },
            getSelectJLDJ() {
                this.fetchSelectList({type: 'JLDJ'}).then(res => {
                    const {code, data: {list}} = res
                    if (code === 200) {
                        this.optionsJLDJ = list || []
                    }
                })
            },
        },

        created() {
            this.fetchDate()
            this.getresumegetList()
            this.getSelectJLDJ()
            this.getSelectYYNL()
        },
        filters: {
            filtersImg: function (img) {
                return basefile + img
            },
            filtersdata: function (e) {
                return formatDate(e, 'Y-M-D')
            },
            filterstype: function (type, data) {
                for (var i = 0; i < data.length; i++) {
                    if (type == data[i].dictNo) {
                        return data[i].dictName
                    }
                }
            },
        },
    }
</script>


<style scoped>
    @import url("P-coach.css");

    .display-flex-column img {
        width: 180px;
        height: 240px;

    }

    .display-flex-column {
        margin-right: 100px;
    }
</style>
<style>
    .el-rate__icon {
        font-size: 22px;
    }

    .star-rate {
        display: flex;
        justify-content: flex-start;
        align-items: center;
    }
</style>
